package com.goods.business.controller;

import com.goods.business.service.ConsummerService;
import com.goods.business.service.SupplierService;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ConsumerVO;
import com.goods.common.vo.business.SupplierVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author jiaoyanlin
 * @Date 2021/11/8 19:52
 * @Description ConsumController
 * 物资来源
 */
@RestController
@RequestMapping("/business")
public class ConsumController {
    @Autowired
    private ConsummerService consummerService;
    @Autowired
    private SupplierService supplierService;
    //物资来源 首页
    @GetMapping("/supplier/findSupplierList")
    public ResponseBean<PageVO<SupplierVO>> findSupplierList(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                                             @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
                                                             @RequestParam Map<String,Object> map){
        PageVO<SupplierVO> pageVO =supplierService.findSupplierList(pageNum,pageSize,map);
        return ResponseBean.success(pageVO);
    }

    //TODO  返回给 添加 入库页面 什么类型的数据呢？
  @GetMapping("/supplier/findAll")
  public ResponseBean<PageVO<SupplierVO>> findAll(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                                  @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
                                                  @RequestParam Map<String,Object> map){

      PageVO<SupplierVO> pageVO =supplierService.findSupplierList(pageNum,pageSize,map);

      return ResponseBean.success(pageVO);
  }
    @PostMapping("/supplier/add")
    public ResponseBean addSupplierVO(@RequestBody SupplierVO supplierVO){
        Boolean flag =supplierService.addSupplierVO(supplierVO);
        if (flag)
            return ResponseBean.success();
        else
            return ResponseBean.error(flag);
    }
    ///edit/13
    @GetMapping("/supplier/edit/{id}")
    public ResponseBean editSupplierVO(@PathVariable Long id){

        SupplierVO supplierVO= supplierService.editSupplierVO(id);

        return ResponseBean.success(supplierVO);
    }
    @PutMapping("/supplier/update/{id}")
    public ResponseBean updateSupplierVO(@RequestBody SupplierVO supplierVO,@PathVariable Long id){
        Boolean flag = supplierService.updateSupplierVO(supplierVO,id);
        if (flag)
            return ResponseBean.success();
        else
            return ResponseBean.error(flag);
    }
    @DeleteMapping("/supplier/delete/{id}")
    public ResponseBean deleteSupplierVO(@PathVariable Long id){
        supplierService.deleteSupplierVO(id);
        return  ResponseBean.success();
    }






    //物资去处 首页
    @GetMapping("/consumer/findConsumerList")
    public ResponseBean<PageVO<ConsumerVO>> findConsumerList(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                                             @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
                                                             @RequestParam Map<String,Object> map){
        PageVO<ConsumerVO> pageVO =consummerService.findConsumerList(pageNum,pageSize,map);
        return ResponseBean.success(pageVO);
    }
  // TODO    this.consumers = res.data;         前端代码   说明 返回的是集合类型
    @GetMapping("/consumer/findAll")
    public ResponseBean<List<ConsumerVO>> findAll(){
        List<ConsumerVO> consumerVOS =consummerService.findAlls();
        return ResponseBean.success(consumerVOS);
    }
   /* public ResponseBean<PageVO<ConsumerVO>> findAllConsumerVO(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                                             @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
                                                             @RequestParam Map<String,Object> map){
        PageVO<ConsumerVO> pageVO =consummerService.findConsumerList(pageNum,pageSize,map);
        return ResponseBean.success(pageVO);
    }*/
    @PostMapping("/consumer/add")
    public ResponseBean add (@RequestBody ConsumerVO consumerVO){
        Boolean flag =consummerService.add(consumerVO);
        if (flag)
            return ResponseBean.success();
        else
            return ResponseBean.error(flag);
    }
    ///edit/13
    @GetMapping("/consumer/edit/{id}")
    public ResponseBean edit(@PathVariable Long id){

        ConsumerVO consumerVO= consummerService.edit(id);

        return ResponseBean.success(consumerVO);
    }
    @PutMapping("/consumer/update/{id}")
    public ResponseBean update(@RequestBody ConsumerVO consumerVO,@PathVariable Long id){
        Boolean flag = consummerService.update(consumerVO,id);
        if (flag)
            return ResponseBean.success();
        else
            return ResponseBean.error(flag);
    }
    @DeleteMapping("/consumer/delete/{id}")
    public ResponseBean delete(@PathVariable Long id){
        consummerService.delete(id);
        return  ResponseBean.success();
    }

}
